﻿@model IEnumerable<BBICMS.Model.Category>
@{
    ViewBag.Title = "菜单";
    ViewBag.PageTitle = ViewBag.Title + "_组件";
}


<div class="main-content">
    <div class="row">
        @foreach (var item in Model)
        {
          
        <div class="col-sm-4">
            <div class="panel panel-default">
                <header class="panel-heading">
                    <h3 class="panel-title">
                        <i class="fa fa-navicon"></i> @item.Title
                    </h3>
                </header>
                <section class="panel-body" id="@string.Format("menu{0}",item.Id)" >
                    @Html.Action("GetMenus", new { categoryId = item.Id})
                </section>
                <footer class="panel-footer">
                    
                </footer>
            </div>
         </div>
        }
    </div>
</div>

<div id="edit-container">
   
</div>

<form id="anti-form" method="post">
    @Html.AntiForgeryToken()
</form>

@section footer {
@Scripts.Render("~/bundles/jqueryvalWithBootstrap")
<script src="~/Content/bootstrap/plugins/bootbox/bootbox.min.js"></script>

        <script>
            function onAjaxBegin() {
                //  $("#divLoading").removeClass("divhide").addClass("divShow");
            }

            function onAjaxComplete() {
                $('#ModalMenuForm').modal();
            }

            function onBeginSave() {
                $("#btnSave i").removeClass("fa-save").addClass("fa-spinner fa-spin")
            }
            function onCompleteSave() {
                $("#btnSave i").removeClass("fa-spinner fa-spin").addClass("fa-save")
            }
            function updateSuccess(data) {

                   switch (data.Status) {
                    case 2:
                        toastr.error(data.Message, '@ViewBag.Title');
                        break;
                    case 1:
                        toastr.success("操作成功", '@ViewBag.Title');
                        $('#ModalMenuForm').modal('hide');
                        setTimeout(function () {
                            location.reload();
                        }, 1000);
                       
                        break;
                    case 4:
                        toastr.warning(data.Message, '@ViewBag.Title')
                        break;
                }


            }


            $(function () {

                //删除数据
                $(document).on("click", '.menuRemove', function (e) {
                    e.preventDefault();
                    var url = $(this).attr('href');
                    //      var confireMes = $(this).attr('data-confirm');
                    var menu = "#menu" + $(this).attr('data-categoryid');
                    var that = $(this);

                    bootbox.setLocale("zh_CN");

                    bootbox.confirm("是否确定删除该项？", function (result) {
                        if (result) {
                            $.post(url, $("#anti-form").serialize(), function (data) {

                                if (data.Status === 1) {
                                    toastr.error(data.Message, '@ViewBag.Title');
                                } else {
                                    toastr.success("已成功删除此项", '@ViewBag.Title');

                                    setTimeout(function () {
                                        location.reload();
                                    }, 1000);
                                }

                            });
                        }
                    });
                });


                //排序向上移动
                $(document).on("click", ".moveMenu", function (e) {
                    var url = $(this).attr('href');
                  //  var menu = "#menu" + $(this).attr('data-categoryid');
                    var that = $(this);
                    e.preventDefault();

                    $.post(url, $("#anti-form").serialize(), function (data) {

                        switch (data.Status) {
                            case 2:
                                toastr.error(data.Message, '@ViewBag.Title');
                                break;
                            case 3:
                                toastr.info(data.Message, '@ViewBag.Title');
                                break;
                            case 1:
                                toastr.success("已成功排位菜单", '@ViewBag.Title');
                                setTimeout(function () {
                                    location.reload();
                                }, 1000);
                        }

                    });
                });



                //显示菜单
                $('.active-item').on("click",".upMove",function (e) {
                    var url = $(this).attr('href');
                    var that = $(this);
                    $.ajax({
                        url: url,
                        dataType: "json",
                        type: "PUT",
                        contentType: 'application/json; charset=utf-8',
                        data: JSON.stringify({}),
                        async: true,
                        processData: false,
                        cache: false,
                        success: function (data) {
                            if (data) {
                                toastr.success('菜单已' + that.attr("title") + '成功！', that.attr("title") + '菜单');

                                if (that.find("span").hasClass('glyphicon-eye-open')) {
                                    that.find("span").removeClass("glyphicon-eye-open").addClass("glyphicon-eye-close");
                                } else {
                                    that.find("span").removeClass("glyphicon-eye-close").addClass("glyphicon-eye-open");
                                }

                            } else {
                                toastr.error('菜单' + that.attr("title") + '失败！', that.attr("title") + '菜单');
                            }
                        },
                        error: function (xhr) {
                            toastr.error('菜单' + that.attr("title") + '失败！', that.attr("title") + '菜单');
                        }
                    });
                    e.preventDefault();
                });
            });
        </script>

    }
